package com.zry.study.config

import android.app.Application
import android.os.Environment
import com.tsy.sdk.myokhttp.MyOkHttp
import com.zry.study.persistentcookiejar.ClearableCookieJar
import com.zry.study.persistentcookiejar.PersistentCookieJar
import com.zry.study.persistentcookiejar.cache.SetCookieCache
import com.zry.study.persistentcookiejar.persistence.SharedPrefsCookiePersistor

import java.io.File
import java.util.concurrent.ExecutorService
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

class MyApplication : Application() {
        /**
         * 线程池
         */
        var cachedThreadPool: ExecutorService = ThreadPoolExecutor(8, 8, 0L,
                TimeUnit.MILLISECONDS, LinkedBlockingQueue(100000),
                ThreadPoolExecutor.CallerRunsPolicy())

        /**
         * 图片保存路径
         */
        var photoSavePath = Environment.getExternalStorageDirectory().absolutePath + "/KYN/image/"
//     var api: IWXAPI? = null

        var myOkHttp: MyOkHttp = MyOkHttp()
        var cookieJar: ClearableCookieJar? = null

        companion object {
                lateinit var instance: MyApplication
                        private set
        }

        override fun onCreate() {
                super.onCreate()
                instance = this
                cookieJar = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(instance))

                val mPhotoFile = File(photoSavePath)
                if (!mPhotoFile.exists()) {
                        mPhotoFile.mkdirs()
                }

        }
	
}
